package com.sunyard.auth.common;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/**
 * @author jinrao
 */
public class GetBeanFactory implements BeanFactoryAware {
    private static BeanFactory beanFactory;

    public static Object getSpringEntry(String beanId){
        return beanFactory.getBean(beanId);
    }
    public static <T>T getSpringEntry(String beanId,Class<T>clazz){
        return clazz.cast(getSpringEntry(beanId));
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        GetBeanFactory.beanFactory = beanFactory;

    }
}
